/**
 * 
 */
package ufpr.mestrado.ais.base.operator.selection;

import ufpr.mestrado.ais.base.VISSolution;
import ufpr.mestrado.ais.base.AISSolutionSet;
import jmetal.base.SolutionSet;
import jmetal.base.operator.comparator.DominanceComparator;
import jmetal.base.operator.selection.Selection;

/**
 * @author bertol
 * 
 */
public class VISBestSolutionSelection extends Selection {

	private VISSolution visSolution_;

	private DominanceComparator comparator_;

	public VISBestSolutionSelection(VISSolution solution) {
		comparator_ = new DominanceComparator();

		visSolution_ = solution;
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = -958774279192203554L;

	/**
	 * Seleciona a melhor solução com base nos requisitos do VIS
	 */
	public Object execute(Object object) {

		SolutionSet solutionSet = (SolutionSet) object;

		if (solutionSet.size() == 0) {
			return null;
		}

		final AISSolutionSet bestSolutions = new AISSolutionSet(solutionSet.size());

		for (int i = 1; i < solutionSet.size(); i++) {
			if (comparator_.compare(visSolution_, solutionSet.get(i)) >= 0)
				bestSolutions.add(solutionSet.get(i));
		}

		return bestSolutions;

	}

}
